package com.ztgf.logistics.api.client.deppon;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.service.shop.IShopContractSettleInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.logistics.models.service.deppon.ILogisticsUserContractService;
import com.ztgf.logistics.models.bo.deppon.LogisticsUserContractBO;
import com.ztgf.logistics.models.dto.deppon.LogisticsUserContractDTO;

import java.util.List;

/**
 * 物流合同关系表控制器
 *
 * @author mxli
 * @Date 2021-09-13 22:17:03
 */

@RestController
@RequestMapping("/api/logisticsUserContract")
@Slf4j
@Api(value = "LogisticsUserContractApiController",tags = "物流合同关系表Api接口")
public class LogisticsUserContractApiController {

    @DubboReference
    private ILogisticsUserContractService logisticsUserContractService;
    @DubboReference
    private IShopContractSettleInService shopContractSettleInService;
    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<LogisticsUserContractDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        LogisticsUserContractDTO dto = logisticsUserContractService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "物流合同关系表列表",notes = "物流合同关系表列表")
    @PostMapping("/queryPageList")
    public Result<Page<LogisticsUserContractDTO>> queryPageList(LogisticsUserContractBO bo){
        Wrapper<LogisticsUserContractDTO> wrapper = new EntityWrapper<>();
                if (bo.getStatus() != null){
                    wrapper.eq("status", bo.getStatus());
                }
        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<LogisticsUserContractDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = logisticsUserContractService.selectPage(page, wrapper);

        return new Result<>(page);
    }


    @PostMapping("/getList")
    @ApiOperation(value = "根据id查找合同列表",notes = "根据id查找合同列表")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<List<LogisticsUserContractDTO>> getList(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        EntityWrapper<LogisticsUserContractDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("shop_id",id);
        wrapper.eq("status",1);
        List<LogisticsUserContractDTO> dto = logisticsUserContractService.selectList(wrapper);

        return new Result<>(dto);
    }
//    @PostMapping("/createDeBangContract")
//    @ApiOperation(value = "根据店铺ID生成德邦合同",notes = "根据店铺ID生成德邦合同")
//    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
//    public Result createDeBangContract(@RequestParam("id") Long id){
//        if(id == null){
//            return new Result<>(CodeEnum.FAIL_100002 );
//        }
//
//        boolean flag = shopContractSettleInService.createDeBangContract(id);
//        if (flag){
//            return new Result<>();
//        }else {
//            EntityWrapper<LogisticsUserContractDTO> wrapper = new EntityWrapper<>();
//            wrapper.eq("shop_id",id);
//            LogisticsUserContractDTO logisticsUserContractDTO=logisticsUserContractService.selectOne(wrapper);
//            if(logisticsUserContractDTO!=null){
//                return new Result<>(CodeEnum.FAIL_COMMODITY_AUDIT_330100);
//            }
//            return new Result<>(CodeEnum.FAIL);
//        }
//    }
//
//    @PostMapping("/gerenateDBSignUrl")
//    @ApiOperation(value = "根据店铺ID获取德邦合同签订地址",notes = "根据店铺ID获取德邦合同签订地址")
//    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
//    public Result gerenateDBSignUrl(@RequestParam("id") Long id){
//        if(id == null){
//            return new Result<>(CodeEnum.FAIL_100002 );
//        }
//
//        String url = "";
//        try {
//            url = shopContractSettleInService.gerenateDBSignUrl(id); //获取合同签订地址
//        } catch (Exception e) {
//            log.info(e.getMessage());
//        }
//
//        if ("".equals(url)){
//            return new Result<>(CodeEnum.FAIL);
//        }else {
//            return new Result<>(url);
//        }
//    }

//    @PostMapping("/getCallBackDeBangContactInfo")
//    @ApiOperation(value = "德邦合同回调",notes = "德邦合同回调")
//    public String getCallBackDeBangContactInfo(@RequestParam(required = false) String content,@RequestParam(required = false) String signature,@RequestParam(required = false) String timestamp) throws Exception {
//        return shopContractSettleInService.getCallBackDeBangContactInfo(signature, timestamp, content);
//    }
}
